Test Remote File
Last Modified: February 25, 2024 18:18 CEST

Test-RemoteFile #

SYNOPSIS #

Checks if a file exists on the remote server, supporting FTP, FTPS, and SFTP protocols.

SYNTAX #

Test-RemoteFile [[-server] <String>] [[-protocol] <String>] [[-port] <Int32>] [-activeMode]
 [[-certificate] <String>] [[-user] <String>] [[-password] <Object>] [[-remoteFolder] <String>]
 [[-remoteFile] <String>] [-ProgressAction <ActionPreference>] [<CommonParameters>]

DESCRIPTION #

The function checks if a file exists on a remote server, supporting the FTP, FTPS (explicit), and SFTP protocols. For SFTP, authentication is supported through username and password or via a certificate. If a certificate is used, the password is considered as a passphrase. Passwords can be provided as plaintext or as a SecureString. For FTP and FTPS, a passive transfer is usually performed, which is always useful when the client is behind a firewall or a NAT router. Alternatively, the active mode can be used.

Please note the requirements and information about FTP, FTPS, and SFTP, as well as SecureString, which we have summarized under Sftp. There you will also find examples for creating a compatible certificate.

EXAMPLES #

Example 1: Tests if the file exists on the remote server #

PS C:\> Test-RemoteFile -server 'myftp.eulanda.eu' -protocol 'sftp' -user 'johndoe' -password '4711' -remoteFolder '/EULANDA' -remoteFile 'test.txt'

The function returns true if the file test.txt exists on the remote server in folder /EULANDA. For authentication, a plaintext password is used along with a username.

PARAMETERS #

-activeMode #

If specified, this switch enables active mode for the FTP or FTPS connection. By default, passive mode is used.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-certificate #

The path to a certificate file for authentication, if using SFTP with certificate-based authentication.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-password #

The password to use for authentication with the remote server. This can be provided as plaintext or as a SecureString.

Type: Object
Parameter Sets: (All)
Aliases:

Required: False
Position: 5
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-port #

The port number to connect to on the remote server. This typically defaults to 21 for FTP and FTPS, or 22 for SFTP if not specified.

Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-protocol #

The protocol to use for the connection, such as FTP, FTPS, or SFTP.

Type: String
Parameter Sets: (All)
Aliases:
Accepted values: ftp, ftps, sftp

Required: False
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-remoteFile #

The file on the remote server to check for existence.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 7
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-remoteFolder #

The path to the folder on the remote server where the remoteFile is to check for existence.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 6
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-server #

The address or hostname of the remote server to connect to.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-user #

The username to use for authentication with the remote server.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters #

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS #

None #

OUTPUTS #

System.Object #

NOTES #