Created
September 12, 2021 13:22
-
-
Save 4ov/61d31c85eec157ac2b2608fe5e29c3d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.ftp | |
import os | |
const( | |
backup_dir = "backup" | |
) | |
fn main(){ | |
println("Connecting...") | |
mut conn := ftp.new() | |
conn.connect('ADDR') or{ | |
panic("${@LINE} Failed to connect: $err") | |
} | |
println('Connected.') | |
conn.login("USER", "PASS") or{ | |
panic("${@LINE} Failed to login: $err") | |
} | |
println('Logged in.') | |
defer{ | |
conn.close()? | |
} | |
println('Creating backup dir') | |
if !os.exists(backup_dir){ | |
os.mkdir(backup_dir)? | |
} | |
conn.cd('blender_filed')? | |
list := conn.dir()? | |
for file in list{ | |
unsafe{ | |
if file.str[0] != `.`{ | |
bytes := conn.get(file)or{ | |
panic("${@LINE} Failed to get file $err") | |
} | |
full_path := os.join_path(backup_dir, file) | |
mut f := os.create(full_path)? | |
f.write(bytes)? | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment