Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Upload to SFTP

$
0
0

Hi,
I have upload script that can upload file into a simple FTP. BUT now i need to upload file into an SFTP, where post number 22 has to be assigned. How to change the code to adapt this need? This is to mention i do not want to use any third-party tool. Any help please?

----------------------------------------------- 

$Ftp = "ftp://files.reuters.com"

# Create a FTPWebRequest object to handle the connection to the ftp server
$ftpRequest = [System.Net.FtpWebRequest]::create($Ftp)
$ftpRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile

# Set the request's network credentials for an authenticated connection
$ftpRequest.Credentials =
    New-Object System.Net.NetworkCredential($Username,$Password) 
 
$ftpRequest.UseBinary = $true
$ftpRequest.UsePassive = $true

# Read the File for Upload
$FileContent = gc -en byte $FileToUpload
$ftpRequest.ContentLength = $FileContent.Length

# Get Stream Request by bytes
$targetFile = $ftpRequest.GetRequestStream()
$targetFile.Write($FileContent, 0, $FileContent.Length)

# Closing the file to complete the upload session
$targetFile.Close()
$targetFile.Dispose()



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>