1
1
I try with this script, but it didn't work for me
$file = "test.txt"
$filePath = "C:\" + $file
$server = "ftp://server"
IF (Test-Connection -ComputerName $server -Quiet -Count 1 -ErrorAction SilentlyContinue)
{
$ftp = $server+$file
$webclient = New-Object System.Net.WebClient
$uri = New-Object System.Uri($ftp)
"Uploading $File..."
$webclient.UploadFile($uri, $filePath)
}
ELSE
{write-host "error"}
when I run the script , I have message "error" in the host it's mean there isn't contact with the server ,but when I ping the server is respond
1How didn't it work? What did it do? Did it do anything? Did you get any error messages? What exactly happens? You can edit your question to add details. – Mokubai – 2017-08-31T09:54:29.247
1
Can
– flolilo – 2017-08-31T11:40:45.263Test-Connection
even be used that way? The documentation states that it Sends ICMP echo request packets ("pings") to one or more computers. and that you have to Type the computer names or type IP addresses in IPv4 or IPv6 format. What I try to say:Test-Connection
won't work withftp://
, but only with the IP/URL itself.what I'm trying to say if ( the server ping) do { upload the file from the path c:\file.txt to the FTP server } else {write "error"} – yazan – 2017-08-31T11:55:17.163
1first check whether ftp port is open $ftpClient = New-Object System.Net.Sockets.TCPClient; $ftpClient.Connect('$server',21); $ftpClient.Connected – Antony – 2017-08-31T13:11:38.423