FTP Get Subfolder name

Hi,

I have a FTP access (hostname, username, password).

I want to get the name of the unique folder (there is only one here) at the root like so:

ftp://hostname//folderName/

Depends on the username, the folder has a different name, that's why I want to get it to copy some files in this one.
There is no access to write anything at this level.

In Python it's simple with the ftplib class:

from ftplib import FTP
ftp = FTP('hostname')
ftp.login('userName','password')
ftp.retrlines('LIST')
ftp.quit()

It prints out the folder name and some other information.

In dotNet, we have the class WebClient, FtpWebRequest, and FtpWebResponse. I'm confused with all these methods.

All I have so far can chek if the connection has succeeded or not, plus the "StatusDescription".
But it's not at all what I am looking for because I have to know the folder name at the start.

clearlistener()
 
FTP = "ftp://hostname//folderName/"
userName = "username"
password = "password"
 
theRemote = FTP + "test.zip"
 
clsRequest = (dotNetClass "System.Net.FtpWebRequest").Create theRemote
clsRequest.Credentials = dotNetObject "System.Net.NetworkCredential" userName password
clsRequest.Method = "STOR" -- "LIST"
 
try
(
    response = clsRequest.GetResponse()
    print (response.StatusDescription)
    response.Close()
    response.Dispose()
    print "Connected"	
)
catch
(
    print "Error"
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Rodman's picture

I found the solution

FTP = "ftp://hostname/"
userName = "username"
password = "password"
 
clsRequest = (dotNetClass "System.Net.FtpWebRequest").Create FTP
clsRequest.Credentials = dotNetObject "System.Net.NetworkCredential" userName password
clsRequest.Method = "LIST"
 
try
(
    response = clsRequest.GetResponse()
    reader = dotNetObject (dotNetClass "System.IO.StreamReader") (response.GetResponseStream())
    print (reader.ReadLine())
    reader.Close()
 
    response.Close()
    response.Dispose()
    print "Connected"   
)
catch
(
    print "Error"
)

Rodman

barigazy's picture

...

What cause error here and you need to use try-cache expression?

bga

Rodman's picture

.

It's a way to know that you couldn't connect to the server.
Maybe there is a better method but I don't know it yet.

Rodman

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.