none
How to download file with variable extension name RRS feed

  • Question

  • here is the code 

                m_ftpClient.UserName = Me.userName.Text
                m_ftpClient.Password = Me.password.Text
    
                    Try
                        ShowFTPResult(m_ftpClient.Download(Me.DownloadFileName.Text, New Uri(("ftp://") + (Me.downloadURI.Text) + ("/aNETWORK.0200"))))
    
    
                    End Try
    
    

    from this code i can download ( aNETWORK.0200 )

    But the problem is the extension ( .0200 ) changing randomly ,, so sometimes the file name became ( aNETWORK.0210 ) some time ( aNETWORK.02222 )

    So how to make the code download it whatever the name is ?

    Wednesday, December 20, 2017 7:55 AM

All replies

  • here is the code 

                m_ftpClient.UserName = Me.userName.Text
                m_ftpClient.Password = Me.password.Text
    
                    Try
                        ShowFTPResult(m_ftpClient.Download(Me.DownloadFileName.Text, New Uri(("ftp://") + (Me.downloadURI.Text) + ("/aNETWORK.0200"))))
    
    
                    End Try

    from this code i can download ( aNETWORK.0200 )

    But the problem is the extension ( .0200 ) changing randomly ,, so sometimes the file name became ( aNETWORK.0210 ) some time ( aNETWORK.02222 )

    So how to make the code download it whatever the name is ?

    I would recommend you first get all the files from the site first using a wild card. Such as aNETWORK.* I haven't had a lot of experience with FTP but on a local folder the code looks like.

    Directory.GetFiles("C:\Restran Conversion\IPSDATA\PM00213A\", "*.*"
    The *.* you can change for needs.


    • Edited by Broggy69 Wednesday, December 20, 2017 3:36 PM
    Wednesday, December 20, 2017 3:35 PM
  • here is the code 

                m_ftpClient.UserName = Me.userName.Text
                m_ftpClient.Password = Me.password.Text
    
                    Try
                        ShowFTPResult(m_ftpClient.Download(Me.DownloadFileName.Text, New Uri(("ftp://") + (Me.downloadURI.Text) + ("/aNETWORK.0200"))))
    
    
                    End Try

    from this code i can download ( aNETWORK.0200 )

    But the problem is the extension ( .0200 ) changing randomly ,, so sometimes the file name became ( aNETWORK.0210 ) some time ( aNETWORK.02222 )

    So how to make the code download it whatever the name is ?

    Sam,

    A few months ago, I put something together for someone else here. You can have a look at the thread here (fair warning -- it's long):

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/d7fd086b-6e09-4bf5-9794-ec7d99e5df23/error-on-systemargumentoutofrangeexception?forum=vbgeneral

    I realize that has nothing to do with your issue here, but that's where it started. Today I've added to it: A method which returns the names and sizes of whatever files it finds there. Obviously that's the starting point to all of this is knowing what's there.

    I have updated the assembly and I have it zipped up here:

    https://fls.exavault.com/share/view/222w-cnydw714

    The first thing to notice here is just like that other thread, you'll want to create the connection information because it has to log in to see just what's there. Following that, just use the shared function and the rest is obvious:

    Imports FTP_RemoteFileInfo
    
    Public Class Form1
        Private Const Server As String = "ftp.fls-online.net"
        Private Const UserName As String = "UploadDownload"
        Private Const Password As String = "Kufru#av5fRa"
    
        Private Sub _
            Form1_Load(sender As System.Object, _
                       e As System.EventArgs) Handles MyBase.Load
    
            Dim connection As New  _
                RemoteServerConnectionInfo(Server, UserName, Password)
    
            Dim remoteFiles As IEnumerable(Of RemoteFile) = _
                FtpMethods.GetRemoteFiles(connection)
    
            If remoteFiles IsNot Nothing Then
                Dim sb As New System.Text.StringBuilder
    
                For i As Integer = 0 To remoteFiles.Count - 1
                    sb.AppendLine(remoteFiles(i).ToString)
    
                    If i < remoteFiles.Count - 1 Then
                        sb.AppendLine()
                        sb.AppendLine("----------")
                        sb.AppendLine()
                    End If
                Next
    
                Dim desktop As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
                Dim fi As New IO.FileInfo(IO.Path.Combine(desktop, "RemoteFiles.txt"))
    
                If fi.Exists Then
                    fi.Delete()
                End If
    
                IO.File.WriteAllText(fi.FullName, sb.ToString)
            End If
    
            Stop
    
        End Sub
    End Class

    This is the text file that it generated:

    http://www.fls-online.net/VBNet_Forum/12-20-17/RemoteFiles.txt

    The connection will handle changing to a remote directory if applicable.

    I hope this helps get you on the right track for the ultimate solution. Using the return value, you should be able to see if "aNETWORK" is in the collection.

    I hope you'll let us all know?



    "A problem well stated is a problem half solved.” - Charles F. Kettering


    • Edited by Frank L. Smith Wednesday, December 20, 2017 7:44 PM ...typos
    Wednesday, December 20, 2017 7:41 PM
  • So how to make the code download it whatever the name is ?

    Hi Sam,

    You mean that you want to download a file without file extension? Or you want to download a file with the same file extension?

    I find Path.GetExtension method can get file extension from some URL, like http://example.com/file.jpg

    For other URL, the filename will be contained as part of the Content-Disposition, a HTTP header that is used to suggest a filename for browsers that display a "save file" dialog. you could take a look the following link:

    https://stackoverflow.com/questions/23228378/is-there-any-way-to-get-the-file-extension-from-a-url

    Get original filename when downloading with WebClient, please refer to:

    https://stackoverflow.com/questions/20492355/get-original-filename-when-downloading-with-webclient

    It is C# code, but you can use any converter tool to convert into vb.net.

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 21, 2017 6:00 AM
    Moderator