By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,903 Members | 1,670 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,903 IT Pros & Developers. It's quick & easy.

FTPWebRequest and CD

P: n/a
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.
Feb 17 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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 wrote:
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.
Feb 17 '07 #2

P: n/a

"William LaMartin" <la******@tampabay.rr.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
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,


Feb 19 '07 #3

P: n/a

"William LaMartin" <la******@tampabay.rr.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
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
Feb 20 '07 #4

P: n/a
>
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
Feb 20 '07 #5

P: n/a
On Feb 16, 11:50 pm, "William LaMartin" <lamar...@tampabay.rr.com>
wrote:
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

Feb 20 '07 #6

P: n/a
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
Feb 20 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.