Check If Path Exists Using Fabric

You can use the files.exists function.

def check_exists(filename):
    from fabric.contrib import files
    if files.exists(filename):
        print('%s exists!' % filename)

And call it with execute.

def main():
    execute(check_exists, '/path/to/file/on/remote')

Although the accepted answer is valid for fabric ver 1, for whoever hits this thread while looking for the same thing but for fabric2:

exists method from fabric.contrib.files was moved to patchwork.files with a small signature change, so you can use it like this:

from fabric2 import Connection
from patchwork.files import exists

conn = Connection('host')
if exists(conn, SOME_REMOTE_DIR):
   do_something()

why not just keep it simply stupid as:

from fabric.contrib.files import exists

def foo():
    if exists('/path/to/remote/file', use_sudo=True):
      # do something...