Command Line - Check if Site is Connected. If it is not, Connect it

Command Line - Check if Site is Connected. If it is not, Connect it

Below and also attached is text for use to check if a drive letter is mapped using WebDrive. If the drive letter is not mapped, WebDrive will then attempt to connect the site.

This may be useful if the drive letter seems to disconnect at times, or simply to ensure the resulting batch file or later commands will succeed by having the letter drive available.


set webdrive="c:\program files\webdriveapp\bin\WebDriveCLI.exe"
set sitename=iiswin10

rem this checks if drive letter W: is defined already or not, use your drive letter here
vol w: >nul 2>nul

if errorlevel 1 (
    @echo Drive is not currently connected
    goto MAPDRIVE

) else (
    echo Drive is already mounted
    goto DOWORK
)

:MAPDRIVE

    @echo mounting site '%sitename%'
    %webdrive% --mount %sitename% --startup --nowait

    @rem check process return code, anything other than 0 means it failed to mount
    if %ERRORLEVEL% GEQ 1 echo Error mounting drive
    echo %ERRORLEVEL%
    if %ERRORLEVEL% GEQ 1 goto EXIT
    @echo drive mounted successfully

:DOWORK

rem enter your commands here
dir w:\


:EXIT

    • Related Articles

    • Guide: Connecting Automatically at Login / System Startup

      To have WebDrive run at startup and connect to a server automatically, ensure these two items in the settings:  1. In the main application Settings, ensure that "Run at startup" is enabled. 2. In the Settings for the specific site you've created in ...
    • Getting Started: Connecting to a Google Drive Server

      Click the “+” icon and select “Google Drive” Enter authentication information as prompted on screen.             This can vary based on account configuration (email, password, 2FA, etc.)             Choose to “Allow” WebDrive access to Google Account ...
    • 2019: Reconnect drive at login/startup is not working

      First, go to Site Properties --> Connection settings for your site profile and ensure that the setting for "Connect at login/startup" is enabled. Next, go to App Settings and ensure that "Run in taskbar tray at startup" is enabled. If the issue ...
    • Getting Started: Creating a new site connection to a server

      In order to use WebDrive to create a connection to a server:  1. Open WebDrive 2. Click the "+" icon in the upper area of the main menu to start adding a new connection 3. Select the appropriate server type for your connection (SFTP, WebDAV, ...
    • Connecting directly to a specific sub folder: Root drive in this folder setting

      If you want to connect directly to a specific sub folder when using WebDrive for any connection EXCEPT for FTP and SFTP, use the "Root drive in this folder" setting. After having created your site in WebDrive, click on the gear icon next to the site ...