GetFileStatus Method

Return status information about a specific file on an FTP server.

Syntax

object.GetFileStatus(FileName [, FileLength] [, FileDate] [, FileOwner] [, FileGroup] [, FilePerms] [, IsDirectory])

The object placeholder represents an expression that evaluates to a FileTransfer object.

Return Type

Integer

Remarks

The GetFileStatus method returns information about the specified file. The filename must be specified using the remote host file naming conventions, and cannot include wildcard characters. The primary difference between using this method and using the OpenDirectory and ReadDirectory methods to obtain file information is that the file status information is returned on the command channel. This method cannot be used while a file transfer is in progress or while a file listing is being returned by the server. All output arguments are optional.

The FileName argument specifies the name of the file that status information is to be returned on.

The FileLength argument specifies the size of the file on the remote host. Note that if this is a text file, the file size may be different on the remote host than it is on the local system. This is because different operating systems use different conventions that indicate the end of a line and/or the end of the file. On MS-DOS and Windows platforms, directories have a file size of zero bytes.

The FileDate argument specifies the date and time the file was created or last modified on the remote host. The date format that is returned is expressed in local time (in other words, the timezone of the remote server is not taken into account) and depends on both the local host settings via the Control Panel and the format of the date and time information returned by the remote host.

The FileOwner argument specifies the owner of the file on the remote host. On some platforms, this information may not be available for security reasons if an anonymous login session was specified.

The FileGroup argument specifies the group that the file owner belongs to. On some platforms, this information may not be available for security reasons if an anonymous login session was specified.

The FilePerms argument specifies the permissions assigned to the file. This value is actually a combination of bits that specify the individual permissions for the file owner, group and world (all other users). For those familiar with UNIX, the file permissions are the same as those used by the chmod command. The permissions are as follows:

Value Constant Description
1 filePermWorldExecute All users have permission to execute the contents of the file. If this permission is set for a directory, this may also grant all users the right to open that directory and search for files in that directory.
2 filePermWorldWrite All users have permission to open the file for writing. This permission grants any user the right to replace the file. If this permission is set for a directory, this grants any user the right to create and delete files.
4 filePermWorldRead All users have permission to open the file for reading. This permission grants any user the right to download the file to the local system.
8 filePermGroupExecute Users in the specified group have permission to execute the contents of the file. If this permission is set for a directory, this may also grant the user the right to open that directory and search for files in that directory.
16 filePermGroupWrite Users in the specified group have permission to open the file for writing. On some platforms, this may also imply permission to delete the file. If the current user is in the same group as the file owner, this grants the user the right to replace the file. If this permission is set for a directory, this grants the user the right to create and delete files.
32 filePermGroupRead Users in the specified group have permission to open the file for reading. If the current user is in the same group as the file owner, this grants the user the right to download the file.
64 filePermOwnerExecute The owner has permission to execute the contents of the file. The file is typically either a binary executable, script or batch file. If this permission is set for a directory, this may also grant the user the right to open that directory and search for files in that directory.
128 filePermOwnerWrite The owner has permission to open the file for writing. If the current user is the owner of the file, this grants the user the right to replace the file. If this permission is set for a directory, this grants the user the right to create and delete files.
256 filePermOwnerRead The owner has permission to open the file for reading. If the current user is the owner of the file, this grants the user the right to download the file to the local system.
4096 filePermSymbolicLink The file is a symbolic link to another file. Symbolic links are special types of files found on UNIX based systems which are similar to Windows shortcuts.

The IsDirectory argument specifies if the file is a directory or regular file.

Note that this method requires that the server return file status information in response to the STAT command. Some servers, for example on VMS platforms, do not provide this information. On some systems, the STAT command will not return information on files that contain spaces or tabs (whitespace) in the filename. In this case, the method will set the specified arguments to empty strings and zero values.

A value of zero is returned if the operation was successful, otherwise a non-zero error code is returned which indicates the cause of the failure.

Example

' Function that generates UNIX representation of file permissions
Private Function FilePerms(dwFilePerms As Long, bIsDirectory As Boolean) As String
    If (dwFilePerms And filePermSymbolicLink) = filePermSymbolicLink Then
        FilePerms = "l"
    ElseIf bIsDirectory Then
        FilePerms = "d"
    Else
        FilePerms = "-"
    End If
    If (dwFilePerms And filePermOwnerRead) = filePermOwnerRead Then
        FilePerms = FilePerms & "r"
    Else
        FilePerms = FilePerms & "-"
    End If
    If (dwFilePerms And filePermOwnerWrite) = filePermOwnerWrite Then
        FilePerms = FilePerms & "w"
    Else
        FilePerms = FilePerms & "-"
    End If
    If (dwFilePerms And filePermOwnerExecute) = filePermOwnerExecute Then
        FilePerms = FilePerms & "x"
    Else
        FilePerms = FilePerms & "-"
    End If
    If (dwFilePerms And filePermGroupRead) = filePermGroupRead Then
        FilePerms = FilePerms & "r"
    Else
        FilePerms = FilePerms & "-"
    End If
    If (dwFilePerms And filePermGroupWrite) = filePermGroupWrite Then
        FilePerms = FilePerms & "w"
    Else
        FilePerms = FilePerms & "-"
    End If
    If (dwFilePerms And filePermGroupExecute) = filePermGroupExecute Then
        FilePerms = FilePerms & "x"
    Else
        FilePerms = FilePerms & "-"
    End If
    If (dwFilePerms And filePermWorldRead) = filePermWorldRead Then
        FilePerms = FilePerms & "r"
    Else
        FilePerms = FilePerms & "-"
    End If
    If (dwFilePerms And filePermWorldWrite) = filePermWorldWrite Then
        FilePerms = FilePerms & "w"
    Else
        FilePerms = FilePerms & "-"
    End If
    If (dwFilePerms And filePermWorldExecute) = filePermWorldExecute Then
        FilePerms = FilePerms & "x"
    Else
        FilePerms = FilePerms & "-"
    End If
End Function
' GetFileStatus method example
txtFileStatus.Text = ""

nError = FileTransfer1.GetFileStatus( _
    strFileName, _
    nFileLength, _
    strFileDate, _
    strFileOwner, _
    strFileGroup, _
    nFilePerms, _
    bIsDirectory)
    
If nError <> 0 Then
    MsgBox "File Status error: " & nError
Else
    strPerms = FilePerms(nFilePerms, bIsDirectory)
    txtFileStatus.Text = strFileName & " " & dwFileLength & " " & _
                         strFileDate & " " & strFileOwner & " " & _
                         strFileGroup & " " & strPerms
End If

        

See Also

CloseDirectory Method, OpenDirectory Method, ReadDirectory Method


Copyright © 2008 Catalyst Development Corporation. All rights reserved.