Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.5k views
in .NET FTP by (180 points)
Hi,

I'm having a strange problem with the FTPClient object. I'm basically looking to backup a few files offsite when they've changed. I go through directory by directory creating as necessary. Then, if the file's lastmodified (on the server) is higher than my local copy, I do a Get(string, string) using the local file path and the remote file name.

In this case it is...
oClient.Get("c:\temp\jason", "hello.txt");

Now, this seems rather obvious, but I keep getting an UnAuthorizedAccessException saying that I do not have access to the path "c:\temp\jason". I looked at permissions, but I don't think that's it since I'm running this in a Windows Forms app which is running under my own (admin) security context. Plus I just created the directory in code, so I should have access to it. I realize, it looks like it isn't related to FTPClient, but perhaps it is.

Do you have a way to change the local working directory (like a LCD)? Also, do you know why this is happening?

9 Answers

0 votes
by (51.6k points)
Try this:
oClient.Get(@"c:\temp\jason", "hello.txt");

or this:
oClient.Get("c:\\temp\\jason", "hello.txt");


If that's not the problem, then try using the stream-based Get method, opening the file-stream using System.IO.File.Create() before you call the method. This will isolate the problem from edtFTPnet since it'll no longer be opening the file itself.

BTW, you probably should be using FTPConnection rather than FTPClient since it offers a more user-friendly interface.

The next version of FTPConnection will have a LocalDirectory property, but the version you have simply uses the current directory as set by System.IO.Directory.SetCurrentDirectory().

- Hans (EDT)
0 votes
by (180 points)
Hi,

Yeah, the code I sent was just a mock up of the actual code. I substituted variables for the "c:\temp\jason" part so that wasn't the issue.

Anyway, I switched all the code to the FTPConnection object as you suggested. I also switched to the stream method and that now works fine.

Thanks!
Jason
0 votes
by (260 points)
I have tried the solution with no success, I keep getting the access denied. I am using the FTPConnection object and used the File.Create to create a file on the local directory and it creates the file, but will not let me copy a file from the ftp server.

Any suggestions. :lol:
0 votes
by (162k points)
You need a full path to a file, not a directory. c:\temp\jason\hello.txt.
0 votes
by (260 points)
You need a full path to a file, not a directory. c:\temp\jason\hello.txt.


I am using the method DownloadFile(localDir, fileName), and localDir has the full path

localDir = "c:\porjectData\projectName\Data"
fileName = "dataFile.txt"

Thanks
:?:
0 votes
by (162k points)
What I mean is you need to set

localDir = @"c:\projectData\projectName\Data\dataFile.txt"
0 votes
by (260 points)
What I mean is you need to set

localDir = @"c:\projectData\projectName\Data\dataFile.txt"


Bruce,
Nout sure what the '@' is for in the variable, but the following is the command that I am using.

localDir = "C:\projectData\projectName\Data"
itm = "dataFile.txt"

ftpOffice.DownloadFile(localDir, itm)

Thanks
Wayne
:?:
0 votes
by (162k points)
Your localDir variable must include the name of the file - it is not a directory but the full path name of the file.
0 votes
by (260 points)
Your localDir variable must include the name of the file - it is not a directory but the full path name of the file


Worked like a charm, thanks

WD
:D

Categories

...