The specified path, file name, or both are too long.

I try to copy three kind of files to a remote location. I've tested it on my own computer and on a server and everything works fine BUT on the computer I actually should execute this script.

I already checked the ExecutionPolicy and it's Ok. The write-host gives mean empty screen. Do get it where the problem lies. Any idea guys?

Here is the error message:

PS C:\Windows\system32> C:\NG_auto_project\Scripts\Get_TXTv3.ps1
C:\NG_auto_project\nextgene_to_import\PA9046_NA_CPKRAS_SN1-193_20131023132639\PA9046_NA_CPKRAS_SN1-193_20131023132639_StatInfo.txt C:\NG_auto_project\nextgene_to_import\AC7449_14A00270-2_ODCL_PRO-98_20140314204739_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\META11A-M2_13A00427-1_OD
DX_SN1-274_20140211193345_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9083_13A01435_ODDX_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9
084_13A01436_ODDX_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9085_13A01441_ODDX_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9154_13A0
1494-1_ODCL_PRO-81_20131128193235_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9165_13A01507-1_ODCL_PRO-81_20131128194449_Mutation_Report.txt C:\NG_aut
o_project\nextgene_to_import\PA9262_13A01673-1_ODCL_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9263_13A01674-1_ODCL_Mutation_Report.txt C:\NG_auto_pr
oject\nextgene_to_import\PA9264_13A01675-1_ODCL_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9266_13A01677-1_ODCL_Mutation_Report.txt C:\NG_auto_projec
t\nextgene_to_import\PA9267_13A01678-1_ODCL_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9268_13A01679-1_ODCL_Mutation_Report.txt C:\NG_auto_project\ne
xtgene_to_import\PA9270_13A01681-1_ODCL_PRO-85_20140108200354_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9362_13A01736-1_ODDX_SN1-241_20140103211849_
Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9363_13A01737-1_ODDX_SN1-241_20140103211901_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA94
27_14A00008-1_ODCL_PRO-89_20140122214642_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9523_14A00105-1_ODDX_SN1-269_20140205150832_Mutation_Report.txt C
:\NG_auto_project\nextgene_to_import\PA9542_14A00184-1_ODDX_SN1-274_20140211193353_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9560_14A00221-1_ODDX_SN
1-276_20140214193028_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9607_14A00271-1_ODCL_PRO-98_20140314204203_Mutation_Report.txt C:\NG_auto_project\nex
tgene_to_import\PA9637_14A00418-1_ODDX_SN1-288_20140304205119_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9638_14A00419-1_ODDX_SN1-288_20140304205140_
Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\PA9670_14A00423-1_ODCL_PRO-98_20140314203402_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\SN214
_BC43_Mutation_Report.txt C:\NG_auto_project\nextgene_to_import\test_Mutation_Report9.txt

Exception calling "Put" with "2" argument(s): "The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters,
and the directory name must be less than 248 characters."
At C:\NG_auto_project\Scripts\Get_TXTv3.ps1:37 char:1
+ $sftp.Put($file, "/files/txt")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : PathTooLongException

The actual script is as following:

#Add the SFTP snap-in
Add-PSSnapin -Name Ktools.PowerShell.SFTP

$FilePatha = "C:\NG_auto_project\nextgene_to_import\*\*"
$FileNameStat = "*_StatInfo.txt"
$Outputa = Get-ChildItem -Path $FilePatha -Filter $FileNameStat | select -ExpandProperty FullName

$FilePathb = "C:\NG_auto_project\nextgene_to_import\"
$FileNameMut1 = "*_Mutation_Report.txt"
$Outputb = Get-ChildItem -Path $FilePathb -Filter $FileNameMut1 | select -ExpandProperty FullName

$Main = "*_Mutation_Report"
$Num = ""
$Ext = ".txt"
for ($Num=0; $Num -lt 50; $Num++)
   
    {$c=$Main + $Num + $Ext
    $d = Get-ChildItem -Path $FilePathb -Filter $c | select -ExpandProperty FullName
    $Outputd = $d
    }


#
#Define SFTP remote Variables
$sftpHost = "xxx.xxx.xxx.xxx"
$userName = "xxxxxx"
$userPassword = "xxxxxx"
$output = "$Outputa","$Outputb","$Outputd"
Write-Host $output | Format-Table Name, Length

#Open the SFTP connection
$sftp = Open-SFTPServer -serverAddress $sftpHost -userName $userName -userPassword $userPassword

#Upload a list of files to another folder on the SFTP server
foreach($file in $output)
{
$sftp.Put($file, "/files/txt")
}

#Close the SFTP connection
$sftp.Close()

Parents
No Data
Reply Children
No Data