FTPWebRequest and CD

  • Thread starter Thread starter William LaMartin
  • Start date Start date
W

William LaMartin

Could someone show me how to use the FtpWebRequest and change to a different
directory? Changing directories is not listed as one of the methods, but I
believe it can be done--just can't figure out how.
 
The methos is:

ftpObject.ChDir(m_sRemotePath)

I just did this for a recent project - it works great. The remote path
is without the \ at the end.

T
 
William LaMartin said:
Could someone show me how to use the FtpWebRequest and change to a
different directory? Changing directories is not listed as one of the
methods, but I believe it can be done--just can't figure out how.

I spent last week downloading a dozen or so examples using ftpwebrequest and
NONE of them worked as downloaded.

I am trying to find out how to use ftpwebrequest.KeepAlive property. The
documentation says
"When the KeepAlive property is set to false, the control connection is
closed when you call the Close method."

BUT there is no accessable close method for ftpwebrequest.

It took me a week to discover that instances of ftpwebrequest can not be
created.

Demilitarized code? Pardon the metaphor.



Respectfully Richard,
 
William LaMartin said:
Could someone show me how to use the FtpWebRequest and change to a
different directory? Changing directories is not listed as one of the
methods, but I believe it can be done--just can't figure out how.

I think I might have found what I have been looking for the
ftpwebrequest.method accepts a "string" value.

I have not tried the standard ftp commands i.e. cd (change directory),
close, etc.

ftpwebrequest.method ="cd"

Richard
 
ftpwebrequest.method ="cd"

The above does not work either.

Have to parse the path name with the directory path then create a new
"ftpwebrequest". AFAIK

Richard
 
Could someone show me how to use the FtpWebRequest and change to a different
directory? Changing directories is not listed as one of the methods, but I
believe it can be done--just can't figure out how.

you cannot use the command directly, but you can modify the uri
parameter to achieve the same result.

Let's say you're using the following format:

String uri = "ftp://myFtpUserName:myFtpUserPassword@myFtpUrl";

FtpWebRequest Request = (FtpWebRequest)WebRequest.Create(uri);

Request.Method = "LIST";

The above example will bring you to your user's directory and list all
the contents there. Now let's say you want to go 2 directories
backwards and list the contents there (provided your user has
permissions to do that). You close the previous FtpWebRequest and
issue a new one with this uri

uri = "ftp://myFtpUserName:myFtpUserPassword@myFtpUrl/%2E%2E/%2E%2E";

This is equivalent to logging in with your user's credentials and then
using cd ../../

Note: if you try using the ".." directly without escaping them the
uri class will strip them, so "ftp://
myFtpUserName:myFtpUserPassword@myFtpUrl/../.." is equivalent to
"ftp://myFtpUserName:myFtpUserPassword@myFtpUrl/"

Now let's say you want to go to another user's directory which is one
level above the root. If you don't specify a user name and password
it's equivalent to logging in as anonymous user. Then you issue a new
FtpWebRequest with the following uri

"ftp://myFtpUrl/%2F/anotherUserDir"

This is equivalent to logging in as anonymous and then doing

Cd /

cd anotherUserDirectory
 
Then you issue a new
FtpWebRequest with the following uri

"ftp://myFtpUrl/%2F/anotherUserDir"

This is equivalent to logging in as anonymous and then doing

Cd /

cd anotherUserDirectory

I understand.

I was hoping there was a way to keep the connection alive between requests.
Like a telnet connection.
The FtpWebRequest class comes with a value "FtpWebRequest.KeepAlive" but it
does not seem to do anything.

I can think of no reason for keeping the connection alive except when
sending passwords in the clear would require sending the password only once
versus every access.

Without spending money for accurate documentation this problem could lead to
be a big waste of time

Thanks,
Richard
 
Back
Top