1
votes

Am trying to copy a file from HP-UX to my Windows machine using PowerShell script.

Please find my script below.

$File = "d:\copiedfile.txt"
$ftp = "ftp://my_Unix_Domain_name/tmp/sourceFile.txt"
"ftp url: $ftp"
$webclient = New-Object System.Net.WebClient
$uri = New-Object System.Uri($ftp)
"Downloading $File..."
$webclient.DownloadFile($uri, $File)

Am able to connected via FTP but, files not copied to my destination directory.

I'm getting an error:

The remote server return ed an error: (550) File unavailable (e.g., file not found, no access).

Not sure, what is wrong in it.

I'm able to download the file using command-line ftp:

ftp> get /tmp/text.sh
200 PORT command successful.
150 Opening ASCII mode data connection for /tmp/test.sh (71 bytes).
226 Transfer complete.
ftp: 76 bytes received in 0.00Seconds 76000.00Kbytes/sec.
ftp>
1
You get some error for sure. What is it? + Can you download the same file using any standalone (even GUI) FTP client? Show us its log file.Martin Prikryl
Am getting this error Exception calling "DownloadFile" with "2" argument(s): "The remote server return ed an error: (550) File unavailable (e.g., file not found, no acces).". But when am trying to get this file manually using ftp am able to get this file from remote location without any issues.Karthikeyan
Again, show us the log file (or output) of the ftp! + Add the information (including the error message) to your question. Do not post important information in comments.Martin Prikryl
When you run your commands or script with ftp, it displays some output. We want to see that.Martin Prikryl
What does get tmp/test.sh (without leading slash) do?Martin Prikryl

1 Answers

1
votes

The .NET implementation of FTP (WebClient or FtpWebRequest) do not consider the slash between hostname and file path to be a part of the file path.

So if you need to use an absolute path to a file (like /tmp/sourceFile.txt) in the URL, you have to add yet another slash:

$ftp = "ftp://my_Unix_Domain_name//tmp/sourceFile.txt"