Link to home
Start Free TrialLog in
Avatar of pvg1975
pvg1975Flag for Argentina

asked on

ftp file with vb.net

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.
SOLUTION
Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pvg1975

ASKER

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

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
Avatar of pvg1975

ASKER

Hi Sammy!

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

Thanks for your answer :)

Paula
Avatar of fredvr666
fredvr666

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