ftp file with vb.net

pvg1975
pvg1975 used Ask the Experts™
on
Hi all,

I need to transfer a file every day at 1 AM thru FTP, just transfer the file (So I dont care about listing, etc).

Can this be done with VB.NET (framework 4) without acquiring a third party component?

I saw some sample code at http://social.msdn.microsoft.com/Forums/da-DK/vblanguage/thread/63796964-f88a-40cf-91eb-08e71e98fa83 but it didnt work.

Thanks!

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Paul MacDonaldDirector, Information Systems
Commented:
Yes, it should be possible.  Any idea why the code sample you linked to didn't work?
Most Valuable Expert 2012
Top Expert 2014
Commented:

Author

Commented:
I ended up using this code which works perfect.

Thanks for your quick answers guys, I will assign you the points.

Paula.

Dim clsRequest As System.Net.FtpWebRequest = _
            DirectCast(System.Net.WebRequest.Create("ftp://ftp.myserver.com/test.txt"), System.Net.FtpWebRequest)
        clsRequest.Credentials = New System.Net.NetworkCredential("myusername", "mypassword")
        clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

        ' read in file...
        Dim bFile() As Byte = System.IO.File.ReadAllBytes("C:\Temp\test.txt")

        ' upload file...
        Dim clsStream As System.IO.Stream = _
            clsRequest.GetRequestStream()
        clsStream.Write(bFile, 0, bFile.Length)
        clsStream.Close()
        clsStream.Dispose()

Open in new window

Top Expert 2011

Commented:
I would use WinSCP
C:\PROGRA~1\WinSCP\WinSCP.exe /command "option confirm off" "open sftp://fulton:fulton9#@ftp.atlantaga.gov" "put C:\DailyQueries\AllQueries_APD.csv "  "exit"

download and install it.

It is usually installed on C:\Program Files\Winscp...

Then all you would need to do is go to windows scheduler, schedule it with this line:

C:\PROGRA~1\WinSCP\WinSCP.exe /command "option confirm off" "open sftp://username:Password@yourdestination" "put C:\thefileToTransfer"  "exit"

Example:

C:\PROGRA~1\WinSCP\WinSCP.exe /command "option confirm off" "open sftp://myusername:mypassword@ftp.mysite.com" "put C:\Folder\file.txt"  "exit"

Then schedule it to transfer daily at your specified time.

That's it

Author

Commented:
Hi Sammy!

There's an application already schedulling a zillion things lol... I just needed to upload a file.

Thanks for your answer :)

Paula
You can make a batch command file, look for auto login here:
http://support.microsoft.com/kb/96269/en-us
or
http://www.walkernews.net/2007/05/08/auto-file-transfer-via-ftp-batch-scripts/
command to upload is:
put myfile.pdf

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial