Question WinSCP - Create one session throughout the whole project?

bentom123

Member
Joined
Feb 22, 2012
Messages
9
Programming Experience
1-3
Hi,

I have a SFTP server that I need to connect to in VB.NET. I will need to be able to transfer files to and from this server within my VB project.

I have this code:

Dim SessionOpts As New WinSCP.SessionOptions SessionOpts.FtpMode = FtpMode.Passive
SessionOpts.FtpSecure = FtpSecure.None
SessionOpts.HostName = "ftpserveraddress"
SessionOpts.PortNumber = "22"
SessionOpts.Protocol = Protocol.Sftp
SessionOpts.UserName = txt_username.Text
SessionOpts.Password = txt_password.Text
SessionOpts.SshHostKeyFingerprint = "ssh-rsa 1024 xx:x:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"


Dim Session As New WinSCP.Session
Session.ExecutablePath = "C:\Tools\WinSCP\WinSCP.exe"



Session.Open(SessionOpts)

This opens a session on my FTP server. Everything works fine.
However, I wish to create another form that I will also use to communicate with the FTP server.

Here's the thing: I don't want to have the session closed when this form closed, and a new one opened when the second form opens. Instead I want a session to be opened on the first form, and the session to be continued on the second form. Is this possible? This would probably require a way of sharing the code throughout the two forms?

How would I go about doing this?

Thanks
 
You need to put the appropriate object somewhere that both forms can access it. There are a number of options available for that. You could use a module or a singleton class. You could also use My.Application. Finally, if you have a main form and it creates these other two forms then the main form can create the object and pass it to those other two forms.
 
Hello Developers!!!
I did finally succeed with winscp + vb.net and freeSSHd server.
The complete design + Pictures + Tips are on the download link.

Megashares - Drag. Drop. Yup. The first site to provide FREE file hosting with drag n drop support.

Megashares - Drag. Drop. Yup. The first site to provide FREE file hosting with drag n drop support.

Please Install all: VB .net 2005 & WinSCP freeSSHd (SFTP server).

http://www.freesshd.com/freeSSHd.exe

Downloading winscp551.zip :: WinSCP


Good luck!!!
 
Back
Top