* Having a good internet line, and less quick to download (or slower) to upload a file to a server, this consideration is very important because occasion could fail if the timeout expires for a connection to the FTP that is usually to have a pessimistic line.
* required fields have in our DB (SQL Server assume) for it to be effective to control such transfers of files, the data as the file name, user name remitenete and destination, time and date of receipt will be the keys to good control.
* Well, needless to say that they have have an FTP server where you store and where "jalaran" files to each user's PC to access them from anywhere in the world and from any era of a very distant future.
This is the code example in Visual Basic 2008
Where path filename would come to be the folder on your hard drive where the downloaded file will be saved and could be "c: \\ downloads \\ nombre_original_segun_BD.doc" Filename and the name which is stored in the FTP server, if we look good parameters would have no trouble getting the file to which you want to access each file and supposedly in the FTP server is registered in Database, here is the importance of keeping the data that are related to the file.
Public Sub DescargarArchivoFTP (ByVal path filename As String , ByVal FileName As String )
Dim LocalFiles As String = path filename
remotefile Dim As String Filename =
Const host As String = "ftp://xxx.xx.xx.xxx/archivos/" 'name of the folder in our server FTP where are the files you want to download
'put the username and password to access the respective server, if it does not possess, let alone the quotes, I mean " "
Const username As String = "user"
Const password As String = "password"
Dim URI As String = host & remotefile 'full name of the file path
Dim ftp As System.Net.FtpWebRequest = CType (Net.FtpWebRequest.Create (URI), Net.FtpWebRequest)
ftp.Credentials = New _
System.Net.NetworkCredential (username, password)
ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
Try
Using response As System.Net.FtpWebResponse = _
CType (ftp.GetResponse, System.Net.FtpWebResponse)
Using responseStream As IO.Stream = response.GetResponseStream
Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
Dim buffer(2047) As Byte
Dim read As Integer = 0
Do
read = responseStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, read)
Loop Until read = 0
responseStream.Close()
fs.Flush()
fs.Close()
End Using
responseStream.Close()
End Using
response.Close()
End Using
Catch ex As Exception
MsgBox (ex.Message)
End Try
End Sub
0 comments:
Post a Comment