EvotecIT/Transferetto

Error: Exception calling "UploadFile" with "3" argument(s): "No such file"

Closed this issue · 8 comments

Hi, I am trying to run to put send files to remote server using sftp but I am facing this error. Can you please help me regarding this ? Thank you.

# Login via credentials
$SftpClient = Connect-SFTP -Server 'host address' -Username 'userName' -Password 'password'

Send-SFTPFile -SftpClient $SftpClient -LocalPath "C:\Users\gurki\Documents\Personal_Projects\Algorithms.txt" -RemotePath "C:\inetpub" -AllowOverride
Disconnect-SFTP -SftpClient $SftpClient

This error is howing up after running the command:


WARNING: Send-SFTPFile - Error: Exception calling "UploadFile" with "3" argument(s): "No such file"


Action     : UploadFile
Status     : False
LocalPath  : C:\Users\gurki\Documents\Personal_Projects\Algorithms.txt
RemotePath : C:\inetpub
Message    : Error: Exception calling "UploadFile" with "3" argument(s): "No such file"

Does that file "C:\Users\gurki\Documents\Personal_Projects\Algorithms.txt" exists?
I believe RemotePath can't be "C:\Inetpub". THere's no "C:" for remote. do a Get-SFTPList and see how it returns data and use it

Send-SFTPFile -SftpClient $SftpClient -LocalPath $File.FullName -RemotePath "/Temporary/$($File.Name)" -AllowOverride

Thank you for suggesting that. It worked for files but if there is folder and and inside it there are some files, it doesn't send that. Do have any suggestions regarding that ?

I have faced this error when I tried to send the assets folder

Screenshot 2022-03-10 140111

Send-SftpDirectory?

This gives me error
Screenshot 2022-03-10 152225
It seems like

FunctionsToExport = @('Compare-FTPFile', 'Connect-FTP', 'Connect-SFTP', 'Connect-SSH', 'Disconnect-FTP', 'Disconnect-SFTP', 'Get-FTPChecksum', 'Get-FTPChmod', 'Get-FTPList', 'Get-SFTPList', 'Move-FTPDirectory', 'Move-FTPFile', 'Receive-FTPDirectory', 'Receive-FTPFile', 'Receive-SFTPFile', 'Remove-FTPDirectory', 'Remove-FTPFile', 'Remove-SFTPFile', 'Rename-FTPFile', 'Rename-SFTPFile', 'Request-FTPConfiguration', 'Send-FTPDirectory', 'Send-FTPFile', 'Send-SFTPFile', 'Send-SSHCommand', 'Set-FTPChmod', 'Set-FTPOption', 'Set-FTPTracing', 'Start-FXPDirectoryTransfer', 'Start-FXPFileTransfer', 'Test-FTPDirectory', 'Test-FTPFile')
, there is not Send-SFTPDirectory command ?

Right, then you probably need to do your own logic - for example:

Import-Module .\Transferetto.psd1 -Force

$SftpClient = Connect-SFTP -Server '192.168.241.187' -Verbose -Username 'test' -Password 'BiPassword90A'
Get-SFTPList -SftpClient $SftpClient | Format-Table
Get-SFTPList -SftpClient $SftpClient -Path "/Temporary" | Format-Table *

$ListFiles = Get-ChildItem -LiteralPath $PSScriptRoot\Upload -Recurse -File
foreach ($File in $ListFiles) {
    $Directory = [io.path]::GetDirectoryName($File.FullName)
    if ($Directory -eq "$PSScriptRoot\Upload") {
        Send-SFTPFile -SftpClient $SftpClient -LocalPath $File.FullName -RemotePath "/Temporary/$($File.Name)" -AllowOverride
    } else {
        Send-SFTPFile -SftpClient $SftpClient -LocalPath $File.FullName -RemotePath "/Temporary/$($Directory.Split('\')[-1])/$($File.Name)" -AllowOverride
    }
}

Disconnect-SFTP -SftpClient $SftpClient

I am getting error because the assets folder doesn't exist on the remote. Do you know command to check if the folder exist on the remote and if not, then create that folder ?

$SftpClient = Connect-SFTP -Server '192.168.241.187' -Verbose -Username 'test' -Password 'BiPassword90A'
Get-SFTPList -SftpClient $SftpClient | Format-Table
Get-SFTPList -SftpClient $SftpClient -Path "/Temporary" | Format-Table *

$ListFiles = Get-ChildItem -LiteralPath $PSScriptRoot\Upload -Recurse -File
foreach ($File in $ListFiles) {
    $Directory = [io.path]::GetDirectoryName($File.FullName)
    if ($Directory -eq "$PSScriptRoot\Upload") {
        Send-SFTPFile -SftpClient $SftpClient -LocalPath $File.FullName -RemotePath "/Temporary/$($File.Name)" -AllowOverride
    } else {
        #$RemotePath = "/Temporary/$($Directory.Split('\')[-1])/$($File.Name)"
        $RemoteFolder = "/Temporary/$($Directory.Split('\')[-1])"
        $List = Get-SFTPList -SftpClient $SftpClient -Path $RemoteFolder -WarningAction SilentlyContinue
        if (-not $List) {
            $SftpClient.CreateDirectory($RemoteFolder)
        }
        Send-SFTPFile -SftpClient $SftpClient -LocalPath $File.FullName -RemotePath "$RemoteFolder/$($File.Name)" -AllowOverride
    }
}

Disconnect-SFTP -SftpClient $SftpClient

Thank you for this solution.
My apologies, I know I keep on asking you questions.
But the above solution doesn't consider for the nested folder paths
For eg:-

folder1
    nestedFolder1
        file1.txt
    nestedFolder2
        file2.txt
    nestedFolder3
        file3.txt
file1.txt
file2.txt

The above solution do copy all the files but it only considers the folder, in which there are files. So, from above example:

nestedFolder1
     file1.txt
nestedFolder2
     file2.txt
nestedFolder3
     file3.txt
file1.txt
file2.txt

Only, these folder and files exist in the remote. the folder1 doesn't exist on the remote. The reason why it is important for folder1 on exist on remote is beacuse I am pushing the build of site generated onto the remote server.

I am not an expert on powershell. Can you please suggest me solution for this ?