0

I have a simple VisualBasic project that downlad file from FTP server. So this is the code to do this:

 Public Sub TestMethod1()
    Dim fileList As New Generic.List(Of String)
    'GET FILE FROM SERVER
    Dim objFTPRequest As FtpWebRequest = CType(FtpWebRequest.Create(New Uri("ftp://ftp.address.it")), FtpWebRequest)
    objFTPRequest.Credentials = New NetworkCredential("user", "pass")
    objFTPRequest.KeepAlive = False
    objFTPRequest.UsePassive = False
    objFTPRequest.UseBinary = True
    objFTPRequest.Method = WebRequestMethods.Ftp.ListDirectory
    
    Dim response As FtpWebResponse = CType(objFTPRequest.GetResponse(), FtpWebResponse)
    Using respStream As StreamReader = New StreamReader(objFTPRequest.GetResponse().GetResponseStream())
        Dim line As String = respStream.ReadLine()
        While line IsNot Nothing
    
        If Regex.IsMatch(line, "^.*\.(pdf|doc|txt|zip|xlsx)$", RegexOptions.IgnoreCase) Then
            'If line Like _config.FileSearch Then
            fileList.Add(line)
        End If
    
        line = respStream.ReadLine()
        End While
    End Using
    
    'DOWNLOAD FILE INTO FILELIST
    For Each fileName As String In fileList
        DownloadFile(fileName)
    Next
    
    
    
    End Sub

Public Function DownloadFile(ByVal pFileName As String) As String
    Dim strPath As String = String.Empty


    Dim objFTPRequestDownload As FtpWebRequest = CType(FtpWebRequest.Create(New Uri("ftp://ftp.address.it/" & pFileName)), FtpWebRequest)
    objFTPRequestDownload.Credentials = New NetworkCredential("user", "pass")
    objFTPRequestDownload.KeepAlive = False
    objFTPRequestDownload.UsePassive = False
    objFTPRequestDownload.UseBinary = True
    objFTPRequestDownload.Method = WebRequestMethods.Ftp.DownloadFile

    Using respDownloadStream As StreamReader = New StreamReader(objFTPRequestDownload.GetResponse().GetResponseStream())
        Using destination As New StreamWriter("D:\" & pFileName)
        destination.Write(respDownloadStream.ReadToEnd())
        End Using
    End Using
    Return strPath
End Function

If I try to run this code from my PC with visualstudio 2010 and .NET framework = 4.0 I can read the all file into my FTP server like this:

file1.txt file2.xlsx ...

And it is ok. But if I try to run this code from another pc with VisualStudio 2010 with .NET framework 4.0, if I try to run my code, the name of file are show in this mode:

10/06/15 12:00AM backup14,252 Cartel1.xlsx

EDIT If I try to inspect on objFTPRequest, I can see the content type on my pc = "" (on my pc works). The content type on another pc, the content type is "html/text" (on another pc not works)

Community
  • 1
  • 1
bircastri
  • 2,169
  • 13
  • 50
  • 119

0 Answers0