0

Can't find much info on this! Remote server returning error (530) not logged in despite providing credentials above. Unsure where I'm going wrong - Powershell novice here. Any help appreciated.

# FTP CREDENTIALS
$FTPUsername = "USER"
$FTPPassword = "PASSWORD"
$FTPHost = "ftp://FTPURI.net"
$FTPSecurePassword = ConvertTo-SecureString -String $FTPPassword -asPlainText -Force
$FTPCredentials = New-Object System.Net.NetworkCredential($FTPUsername,$FTPSecurePassword)


#Start FTP Webrequest and configure 
$ftp=[System.Net.FtpWebRequest]::Create("$FTPHost")
$ftp.Credentials=$FTPCredentials
$ftp.UseBinary = $true
$ftp.UsePassive = $true

#Folder with new ESL
$NewESLDir = "\\egregorio\Staging\ESLOffice3.17\Release Candidate\Codebase\wwwroot"

#FTP Directory to upload Files
$destination = "ftps:/**********@***********/site/TESTING"

#Create WebClient
$webclient = New-Object -TypeName System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($FTPUsername,$FTPSecurePassword)

#Define which files/ folders we are to upload
$Entries = Get-ChildItem $NewESLDir -Recurse
$Folders = $Entries | Where-Object{$_.PSIsContainer}
$Files = $Entries | Where-Object{!$_.PSIsContainer}

# Create Directories in FTP if needed (help me please)
foreach ($folder in $Folders)
{    
    $FolderPath = $NewESLDir  -replace "\\","\\" -replace "\:","\:"   
    $DesFolder = $folder.Fullname -replace $FolderPath,$FTPHost
    $DesFolder = $DesFolder -replace "\\", "/"
    # Write-Output $DesFolder

    try
        {
            $makeDirectory = [System.Net.WebRequest]::Create($DesFolder);
            $makeDirectory.Credentials = New-Object System.Net.NetworkCredential($FTPUsername,$FTPSecurePassword);
            $makeDirectory.Method = [System.Net.WebRequestMethods+FTP]::MakeDirectory;
            $makeDirectory.GetResponse();
            #folder created successfully
        }
    catch [Net.WebException]
        {
            try {
                #if there was an error returned, check if folder already existed on server
                $checkDirectory = [System.Net.WebRequest]::Create($DesFolder);
                $checkDirectory.Credentials = New-Object System.Net.NetworkCredential($FTPUsername,$FTPSecurePassword);
                $checkDirectory.Method = [System.Net.WebRequestMethods+FTP]::PrintWorkingDirectory;
                $response = $checkDirectory.GetResponse();
                #folder already exists!
                }
    catch [Net.WebException] 
            {
                #if the folder didn't exist
            }
        }
}
# Upload Files - Start
foreach($entry in $Files)
{
    $Fullname = $entry.fullname
    $Name = $entry.Name
    $FilePath = $UploadFolder -replace "\\","\\" -replace "\:","\:"
    $DesFile = $Fullname -replace $FilePath,$FTPHost
    $DesFile = $DesFile -replace "\\", "/"
    # Write-Output $DesFile

    $uri = New-Object System.Uri($DesFile) 
    $webclient.UploadFile($uri, $Fullname)
}
# Upload Files - Stop

As you can see my credentials are input above, It's erroring out at line 76 (the " $webclient.UploadFile($uri, $Fullname)"), but I above I put in webclient.credentials so Im not sure when I'm not logged in. This is my first time posting to stack overflow, and I'm only doing so out of desperation! Sorry for

0 Answers0