Avatar of Chris Jones
Chris Jones
Flag 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
Visual Basic.NET.NET ProgrammingVB Script

Avatar of undefined
Last Comment
Chris Jones

8/22/2022 - Mon
the_endjinn

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
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

the_endjinn

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

Your help has saved me hundreds of hours of internet surfing.
fblack61
Chris Jones

ASKER
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
the_endjinn

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
the_endjinn

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.
Chris Jones

ASKER
wait it was line in my code as well sorry.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Chris Jones

ASKER
the Robo-FTP  is a great ideal but more than what i was neding but may use it in another program.