0 Pluspunkte 0 Minuspunkte
Wie lade ich mit Powershell eine Datei auf einen FTP Server hoch?
von  

2 Antworten

0 Pluspunkte 0 Minuspunkte

Du kannst einen FtpWebRequest in Powershell ausführen.

# Datei als Test.pdf auf dem Server speichern
$ftpRequest = [System.Net.FtpWebRequest]::Create("ftp://mein-server.de/Test.pdf")

# Credentials
$ftpRequest.Credentials = New-Object System.Net.NetworkCredential("admin", "t0ps3cr3t")
$ftpRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile

# Local file c:\File.pdf
$localContent = [System.IO.File]::ReadAllBytes("C:\File.pdf")
$ftpStream = $ftpRequest.GetRequestStream()
$ftpStream.Write($localContent, 0, $localContent.Length)
$ftpStream.Close()

$ftpResponse = $ftpRequest.GetResponse()
$ftpResponse.Close()
von  
0 Pluspunkte 0 Minuspunkte

Mit dem eingebauten FTP Befehl.

PS > ftp ftp.server.com
user: *****
password: *****
...
230 Aktuelles Verzeichnis ist /
ftp>
von