This is an old revision of the document!
put command
Uploads one or more files from local directory to remote directory.
import pygame import time import random
# Initialize pygame pygame.init()
Advertisement
# Colors white = (255, 255, 255) yellow = (255, 255, 102) black = (0, 0, 0) red = (213, 50, 80) green = (0, 255, 0) blue = (50, 153, 213)
# Display dimensions width = 600 height = 400
# Create the display win = pygame.display.set_mode1 pygame.display.set_caption(’Snake Game’)
# Clock and font clock = pygame.time.Clock() snake_block = 10 snake_speed = 15
font_style = pygame.font.SysFont(“bahnschrift”, 25) score_font = pygame.font.SysFont(“comicsansms”, 35)
def your_score(score):
value = score_font.render("Score: " + str(score), True, black) win.blit(value, [0, 0])
def draw_snake(snake_block, snake_list):
for x in snake_list: pygame.draw.rect(win, green, [x[0], x[1], snake_block, snake_block])
def message(msg, color):
mesg = font_style.render(msg, True, color) win.blit(mesg, [width / 6, height / 3])
def gameLoop():
game_over = False game_close = False
Advertisement
# Snake starting position x1 = width / 2 y1 = height / 2
# Movement x1_change = 0 y1_change = 0
# Snake body list snake_List = [] Length_of_snake = 1
# Food foodx = round(random.randrange(0, width - snake_block) / 10.0) * 10.0 foody = round(random.randrange(0, height - snake_block) / 10.0) * 10.0
while not game_over:
while game_close: win.fill(blue) message("You lost! Press Q-Quit or C-Play Again", red) your_score(Length_of_snake - 1) pygame.display.update()
for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: game_over = True game_close = False if event.key == pygame.K_c: gameLoop()
for event in pygame.event.get(): if event.type == pygame.QUIT: game_over = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT and x1_change == 0: x1_change = -snake_block y1_change = 0 elif event.key == pygame.K_RIGHT and x1_change == 0: x1_change = snake_block y1_change = 0 elif event.key == pygame.K_UP and y1_change == 0: y1_change = -snake_block x1_change = 0 elif event.key == pygame.K_DOWN and y1_change == 0: y1_change = snake_block x1_change = 0
Advertisement
# Check boundaries if x1 >= width or x1 < 0 or y1 >= height or y1 < 0: game_close = True
# Move snake x1 += x1_change y1 += y1_change win.fill(blue) pygame.draw.rect(win, yellow, [foodx, foody, snake_block, snake_block])
# Update snake list snake_Head = [x1, y1] snake_List.append(snake_Head) if len(snake_List) > Length_of_snake: del snake_List[0]
# Check collision with self for x in snake_List[:-1]: if x == snake_Head: game_close = True
draw_snake(snake_block, snake_List) your_score(Length_of_snake - 1)
pygame.display.update()
# Check if snake eats food if x1 == foodx and y1 == foody: foodx = round(random.randrange(0, width - snake_block) / 10.0) * 10.0 foody = round(random.randrange(0, height - snake_block) / 10.0) * 10.0 Length_of_snake += 1
clock.tick(snake_speed)
Advertisement
pygame.quit() quit()
# Run the game gameLoop()
Remarks
If only one parameter is specified, uploads the file to remote working directory. If more parameters are specified, all except the last one specify set of files to upload. Filename can be replaced with Windows wildcard2 to select multiple files. To upload all files in a directory, use mask *
.
The last parameter specifies target remote directory and optionally operation mask to store file(s) under different name. Target directory must end with slash. To upload more files to current working directory use ./
as the last parameter.
With the /stdin
command-line switch, -
can be used as a source to stream the standard input of winscp.com
to remote server. Streaming is supported with the SFTP and FTP protocols only.
When specific file name is used, command fails when the file does not exist. When wildcard is used, command succeeds, without doing anything, if the wildcard does not match any file, by default (you can change this using option failonnomatch on
command).
You can have WinSCP generate a code template for put
for you.
See also synchronize
, if you need to transfer modified files only.
Switches:
Switch | Description |
---|---|
-delete |
Delete source local file(s) after a successful transfer. |
-latest |
Uploads the latest file from the files selected by the file , file2 … parameters (typically file masks) only. |
-resume |
Automatically resume transfer if possible.3 SFTP and FTP protocols only. Cannot be combined with -append . Has no effect when streaming (- source). |
-append |
Append source file to the end of target file. SFTP protocol only. Cannot be combined with -resume . |
-preservetime |
Preserve timestamp. |
-nopreservetime |
Do not preserve timestamp. |
-permissions=<mode> |
Set permissions (SFTP and SCP protocols only). Has no effect when streaming ( - source). |
-nopermissions |
Keep default permissions. |
-speed=<kbps> |
Limit transfer speed (in KB/s). |
-transfer=<mode> |
binary|ascii|automatic Transfer mode: binary, ascii (text), automatic (by extension). |
-filemask=<mask> |
<mask>[;<mask2>...] Sets file mask. |
-resumesupport=<state> |
on|off|<threshold> Configures automatic resume/transfer to temporary filename. |
-neweronly |
Transfer new and updated files only. See also synchronize command. |
-rawtransfersettings setting1=value1 setting2=value2 … |
Allows configuring any transfer settings using raw format as in an INI file. E.g. to enable preserving of directory timestamps, use -rawtransfersettings PreserveTimeDirs=1 . The switch should come only after other parameters. |
Advertisement
Aliases: send
, mput
Effective options: confirm
, reconnecttime
, failonnomatch
XML log elements: upload
, mkdir
, chmod
(with -permissions
), touch
(with -preservetime
)
Examples
put index.html
put -delete index.html about.html ./
put -permissions=644 index.html about.html /home/martin/public_html/
put d:\www\index.html about.*
put *.html *.png /home/martin/backup/*.bak
put -filemask=*.html -resumesupport=on *
Converting to .NET Assembly
When converting script to .NET Assembly, map put
command to Session.PutFiles
method.
Parameters mapping: Command parameter file
maps to method parameter localPath
. When multiple source file parameters are used, you need to call Session.PutFiles
multiple times. Command parameter directory/newname
maps to method parameter remotePath
. You have to convert relative paths to absolute paths.
Switches mapping:
Switch | Mapping |
---|---|
-delete |
Value true ($True in PowerShell) for method parameter remove . |
-latest |
See Uploading the most recent file. |
-resume -append -preservetime -nopreservetime -permissions -nopermissions -transfer -filemask -resumesupport -speed=<kbps> |
Converting transfer settings scripting switches to .NET assembly class TransferSettings . |
-neweronly |
Not supported. Use Session.SynchronizeDirectories instead. |
To emulate the (default) option batch abort
mode, call TransferOperationResult.Check
on method’s result. See also Capturing results of operations.
Advertisement
For example, following script snippet:
cd /home/martinp lcd d:\ ... put -delete -filemask=*>1M -resumesupport=off *.txt *.xml web/
maps to following PowerShell code:
$transferOptions = New-Object WinSCP.TransferOptions # -filemask=*>1M $transferOptions.FileMask = "*>1M" # -resumesupport=off $transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off # Absolute paths + $True for -delete + Two calls for two source parameters # + calling Check on result to emulate the (default) "option batch abort" mode $session.PutFiles("d:\*.txt", "/home/martinp/web/", $True, $transferOptions).Check() $session.PutFiles("d:\*.xml", "/home/martinp/web/", $True, $transferOptions).Check()
- width, heightBack
- The Windows wildcard supports
*
and?
only. If you want to use a full syntax of file masks, use a-filemask
switch.Back - Applies for individual files transfers only. It does not skip transfer of fully transferred files. For that, combine the switch with
-neweronly
.Back