Link to home
Create AccountLog in
Avatar of Chris Jones
Chris JonesFlag for United States of America

asked on

how to ftp using a https address in vb

hello

I have this vb.net [program and i had it working perfect using plain ftp but the company changed the way they supply the file so now its ftp over https.how would i do that in vb.net
Avatar of the_endjinn
the_endjinn
Flag of United Kingdom of Great Britain and Northern Ireland image

The ftpwebrequest class has an enablessl property that allows use of SSL over FTP. Please see the below to check if it is what you are after. Also, FTP and HTTPS are different protocols, it's either one or the other and you can't encapsulate FTP  over HTTPS.

FtpWebRequest request = WebRequest.Create(ftp://myftpserver/dir/filename);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.EnableSsl = true; // Here you enabled request to use ssl instead of clear text
WebResponse response = request.GetResponse();

Open in new window


Class info at MSDN
Avatar of Chris Jones

ASKER

ok i get this error when i do that

Unable to cast object of type 'System.Net.HttpWebRequest' to type 'System.Net.FtpWebRequest'.

This is the httpaddress

https://ets-scorelink.ets.org/edsasftp/TOEFL/TOE6188.TST

That would indicate that you are indeed just using HTTPS with no FTP involved.

Try the following instead

request = WebRequest.Create(https://ets-scorelink.ets.org/edsasftp/TOEFL/TOE6188.TST);
HTTPWebResponse response = request.GetResponse();

Open in new window


If you need to supply credentials then you would have to set the Credentials property of the request before the request.GetResponse line, similar to the below.

request.Credentials = NetworkCredential("Username", "Password");

Open in new window

hmm this is what i have where should i put this cod3e or what code needs to be replaced. Also the  varable link is the URL



Dim FTPRequest As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(line), System.Net.FtpWebRequest)
                    FTPRequest.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
                    FTPRequest.EnableSsl = True
                    Dim response As System.Net.FtpWebResponse = DirectCast(FTPRequest.GetResponse(), System.Net.FtpWebResponse)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of the_endjinn
the_endjinn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
I've just noticed that I've put "line" rather than "link" as the variable in the WebRequest.Create as I copied that section from the comment.
wait it was line in my code as well sorry.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
the Robo-FTP  is a great ideal but more than what i was neding but may use it in another program.