//
you're reading...
IT-Center, VB.NET

VB.NET FTP Client Auto Upload

Before discuss FTP client upload source code, the first must be understanding type of FTP Server mode, first is Active mode and Passive mode for second.

Passive mode

In passive mode, the client has no control over what port the server chooses for the data connection. Therefore, in order to use passive mode, you’ll have to allow outgoing connections to all ports in your firewall.

Active mode

In active mode, the client opens a socket and waits for the server to establish the transfer connection.

See : http://wiki.filezilla-project.org/Network_Configuration

The source code is here :

' sHost = url:port/folder/filename
Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(sHost & "/" & sFile), System.Net.FtpWebRequest)

' only for PASV mode 
' request.UsePassive = False

request.Credentials = New System.Net.NetworkCredential(sFTPUser, sFTPPwd)
 request.Method = System.Net.WebRequestMethods.Ftp.UploadFile

' sFile is filename 
Dim file() As Byte = System.IO.File.ReadAllBytes(sFile)
 Dim strz As System.IO.Stream = request.GetRequestStream()
 strz.Write(file, 0, file.Length)
 strz.Close()
 strz.Dispose()

if you have problem .GetRequestStream() is error 421 can not create socket, please FTP mode PASV/ACTIVE. If you want auto upload can combine with Timer Controler

About berbagisolusi

Berbagi merupakan sebuah bentuk simbol keikhlasan untuk membantu dan menolong, sedangkan solusi adalah cara menyelesaikan masalah. Setiap manusia pasti mengalami masalah, tetapi kita tidak perlu mengalami masalah yang sama jika orang lain pernah mengalami dan kita tahu hal tersebut.

Discussion

One thought on “VB.NET FTP Client Auto Upload

  1. This has to be my favorite FTP Library for VB.NET:
    https://www.kellermansoftware.com/p-39-net-ftp-library.aspx

    Posted by Sammie Asava | April 6, 2013, 4:57 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

December 2012
M T W T F S S
« Nov   Sep »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Archives

Web Statistic

Blog Stats

  • 149,580 hits
%d bloggers like this: