EnableSsl = True Error for FTP

Discussion in 'Visual Studio' started by Miro, May 7, 2009.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I was able to get code from the web to create an "FTP" from my vb.net exe to my discountasp.net account.

    It works great, (code below) but I have read this on msdn:
    ---
    http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.enablessl.aspx
    Caution:
    Unless the EnableSsl property is true, all data and commands, including your user name and password information, are sent to the server in clear text. Anyone monitoring network traffic can view your credentials and use them to connect to the server. If you are connecting to an FTP server that requires credentials and supports SSL, you should set EnableSsl to true.
    ---

    So I set my enablessl code to true and I get an exception error:
    Exception error: The remote certificate is invalid according to the validation procedure.
    Without it being set to True the code works without errors.

    I am running with discountasp.net a windows server 2008 and it specifies that:
    NEW FTP over SSL
    - only on Windows 2008 Hosting Platform

    I must be missing some setup somehwere?

    Thanks,

    Miro




    =======Code=====
    Sub UploadFile(ByVal path As String, ByVal filename As String)
    Dim ftpsite As String = "ftp://ftp.myhostingaccount.discountasp.net/"
    Dim local_file As String = path & filename
    Dim remote_file As String = ftpsite & "/uploadfolder/" & filename
    Dim user_name As String = "9999999|auser"
    Dim password As String = "userpassword"

    'Variables
    Dim cls_request As System.Net.FtpWebRequest = _
    DirectCast(System.Net.WebRequest.Create(remote_file), System.Net.FtpWebRequest)

    'Establish credentials for logging into ftp site
    cls_request.Credentials = New System.Net.NetworkCredential(user_name, password)

    'Set properties
    ====================with this line on, line below marked fails
    cls_request.EnableSsl = True
    ====================
    cls_request.KeepAlive = False
    cls_request.Proxy = Nothing
    cls_request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
    cls_request.UseBinary = True

    'Read in the file
    Dim b_file() As Byte = System.IO.File.ReadAllBytes(local_file)

    'Upload the file
    ====================this line fails with an exception if above line is set to true
    Exception error: The remote certificate is invalid according to the validation procedure.

    Dim cls_stream As System.IO.Stream = cls_request.GetRequestStream()
    ====================
    cls_stream.Write(b_file, 0, b_file.Length)
    cls_stream.Close()
    cls_stream.Dispose()

    End Sub
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    hmm.. i never tried to create code to FTP over SSL.. i'll do some research and will post if i find something.
     
  3. Im a newbie...so I may be doing something entirly wrong as well...but I wonder if it has to do with the discountasp.net certificate.

    If I change my filezilla to upload a file using the ssl as stated here:
    https://support.discountasp.net/KB/a318/how-to-set-up-filezilla-to-use-ftp-over-ssl.aspx?KBSearchID=33190
    Then filezilla connects but there is a certificate warning:

    "Unknown Certificate"
    The server's certificate is unknown. Please carefully examine teh certificate to make sure the server can be trusted ......

    And I must manually accept the certificate.
    I wonder if somehow in vb2008.net i must do the same.

    Im too much of a newbie to know

    Thanks for replying

    Cheers'

    Miro
     
  4. This error ususally pops up when the URL you are using is not matching with the common name on the SSL certificate
     
  5. What should the path be for the ftp certificate?

    I am using this right now as my two paths for the code above:

    Dim local_file As String = path & filename
    Dim remote_file As String = ftpsite & "/pokerupload/" & filename

    The two parameters being passed into the function are as follows:
    "C:\aspnettest\", "testupload.txt"

    so
    Sub UploadFile(ByVal path As String, ByVal filename As String)
    is basically
    Sub UploadFile("C:\aspnettest\", "testupload.txt" )

    Basically I created a poker timer for a buddy and want it to push a file once the game is done online.
    Right now its just a test txt file, but the path works fine when I dont have ssl on.

    So How can I find out what the proper path should be that is "allowed" to be used ?

    Thanks,

    Miro
     
  6. Sorry, forgot to metion, that the ftp path I am using is this:
    Dim ftpsite As String = "ftp://ftp.companyorange.com/"
     
  7. I use FileZilla for my FTP application and it reports the URL it uses is "ftpes://{account_num|username}@ftp.site.com" and I use SSL over FTP. You could try replacing ftp:// with ftpes://. I hope that helps.
     
  8. I also use filezilla.
    -Tried to put the ftpes:// path
    into the code and it gets an exception error:
    The URI prefix is not recognized.

    at this line:
    Dim cls_request As System.Net.FtpWebRequest = _
    DirectCast(System.Net.WebRequest.Create(remote_file), System.Net.FtpWebRequest)


    No worries...
    ill ftp for now without it and hopefully someone else might be trying what I am.
     
  9. Bruce

    Bruce DiscountASP.NET Staff

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page