# Unable to connect to company FTP

**URL:** <https://forums.powershell.org/t/unable-to-connect-to-company-ftp/17042>\
**Category:** PowerShell Help\
**Created:** [July 10, 2021, 8:38am UTC](https://forums.powershell.org/t/unable-to-connect-to-company-ftp/17042 "2021-07-10T08:38:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DankyDuck82](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@DankyDuck82](https://forums.powershell.org/u/DankyDuck82)\
**Post date:** [July 10, 2021, 8:38am UTC](https://forums.powershell.org/t/unable-to-connect-to-company-ftp/17042/1 "2021-07-10T08:38:55Z")

</div>

I am still new at PowerShell, so be gentle 🙂

I have for some time now been trying to connect to a FTP, but no matter how many different scripts i tried, none of them work, I think I might have tried +10 different scripts but i keep running into errors like:

_Set-FTPConnection : Exception calling “GetResponse” with “0” argument(s): “Unable to connect to the remote server”_

_Set-FTPConnection : Exception calling “GetResponse” with “0” argument(s): “The remote certificate is invalid according to the validation procedure.”_

_New-SFTPSession : Connection failed to establish within 10000 milliseconds._

The most promising script i found is this one:

```auto
#This function configures the necessary details for the script to connect to the FTP server 
function ConnectFTP () 
{ 
	$User = "USERNAME" 
	$Pass = "PASSWORD" 
	$EncryptedPass = ConvertTo-SecureString -String $Pass -asPlainText -Force 
	$Credentials = New-Object System.Management.Automation.PSCredential($User,$EncryptedPass) 
	$Server = "HOSTNAME" #THE FTP DOES NOT USE DEFAULT PORT, UNSURE WHERE TO ADD PORT NO ?
	
	#Connect to FTP site 
	#Store the connection output into a variable called $ResponseStatus 
	$ResponseStatus = Set-FTPConnection -Credentials $Credentials -Server $Server -Session MySession -UsePassive 
	
	#Evaluate the contents of $ResponseStatus using ConnectionStatus function 
	if (ConnectionStatus $ResponseStatus -eq $True) 
	{ 
		#If the connection was successful, list the files in the given path 
		Get-FTPChildItem -Session MySession -Path ftp://HOSTNAME/FOLDER
	} 
	
	else 
	{ 
		#If the connection failed, write the below string to screen 
		Write-Host "Connection to FTP server failed!" 
	} 
} 

#This function will parse the content of a required parameter $ResponseStatus 
function ConnectionStatus ($ResponseStatus) 
{ 
	#If $ResponseStatus contains the string "*Successfully transferred*", then the connection is considered successful 
	if (($ResponseStatus | Select -ExpandProperty StatusDescription) -like "*Successfully transferred*") 
	{ 
		#Success 
		#By returning $True back to the function that called this function, we can step into the if/else condition in the ConnectFTP function 
		return $True 
	} 
	
	else 
	{ 
		#Fail return $False 
	} 
}
	 
#Program Starts Here 
ConnectFTP

```

This script results in:

```auto
Set-FTPConnection : Exception calling "GetResponse" with "0" argument(s): "Unable to connect to the remote server"
At D:\Routines\ftpv5.ps1:12 char:20
+ ... nseStatus = Set-FTPConnection -Credentials $Credentials -Server $Serv ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Set-FTPConnection

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [July 10, 2021, 11:04am UTC](https://forums.powershell.org/t/unable-to-connect-to-company-ftp/17042/2 "2021-07-10T11:04:38Z")

</div>

Daniel,  
Welcome to the forum.

When you have problems with scripts or modules you have found in the internet for example in the PowerShellGallery you should contact the outhor first and try to ask there for help.

---

<div class="post-metadata">

**Author:** ![DankyDuck82](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@DankyDuck82](https://forums.powershell.org/u/DankyDuck82)\
**Post date:** [July 10, 2021, 4:35pm UTC](https://forums.powershell.org/t/unable-to-connect-to-company-ftp/17042/3 "2021-07-10T16:35:37Z")

</div>

Hi Olaf,  
Thank you.

Okay, that makes sense. The scripts articel is +2 years old, but maybe I will get lucky.

---

<div class="post-metadata">

**Author:** ![jlogan3o13](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@jlogan3o13](https://forums.powershell.org/u/jlogan3o13)\
**Post date:** [July 11, 2021, 4:41pm UTC](https://forums.powershell.org/t/unable-to-connect-to-company-ftp/17042/4 "2021-07-11T16:41:24Z")

</div>

@DankyDuck82 Let’s take it a step at a time. If you open PS, type in ftp, then use the open command, does it work? Something like this:

![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/8/8eb4cd80f88275cee43266f32afe166f964378d7.png)

---

<div class="post-metadata">

**Author:** ![DankyDuck82](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@DankyDuck82](https://forums.powershell.org/u/DankyDuck82)\
**Post date:** [July 11, 2021, 5:05pm UTC](https://forums.powershell.org/t/unable-to-connect-to-company-ftp/17042/6 "2021-07-11T17:05:41Z")

</div>

![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/5/5b0bc59b2727ad2fd5ada37fc43efc77b892f4b3.png)

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [July 12, 2021, 9:37am UTC](https://forums.powershell.org/t/unable-to-connect-to-company-ftp/17042/7 "2021-07-12T09:37:23Z")

</div>

Pretty sure (it’s a long time since I used it) the native `ftp` command does not support FTPS.

Your first post mentions `New-SFTPSession` and SFTP is not FTP. The key differences are:

- FTP - No encryption
- FTPS - FTP with TLS encryption
- SFTP - FTP over SSH

I’m assuming your `Set-FTPConnection` is from the PSFTP module. If so, try the command using the `-EnableSSL` and `-IgnoreCert` parameters.

Have you checked you can connect using a FTP client such as WinSCP?

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:23pm UTC](https://forums.powershell.org/t/unable-to-connect-to-company-ftp/17042/8 "2024-05-16T20:23:50Z")

</div>


