Skip to content

Commit 0514147

Browse files
committed
Adding send and download to runpod pod CLI
1 parent eac280d commit 0514147

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

runpod/cli/groups/pod/commands.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
RunPod | CLI | Pod | Commands
33
'''
44
import click
5+
import os
56
from prettytable import PrettyTable
67

78
from runpod import get_pods, create_pod
@@ -58,3 +59,65 @@ def connect_to_pod(pod_id):
5859
click.echo(f'Connecting to pod {pod_id}...')
5960
ssh = ssh_cmd.SSHConnection(pod_id)
6061
ssh.launch_terminal()
62+
63+
@pod_cli.command("send")
64+
@click.argument("pod_id", required=True)
65+
@click.argument(
66+
"local_path",
67+
required=True,
68+
type=click.Path(exists=True, file_okay=True, dir_okay=False),
69+
)
70+
@click.argument("remote_path", required=True)
71+
def send_file(pod_id, local_path, remote_path):
72+
"""
73+
Send a local file to a specified pod.
74+
...
75+
"""
76+
try:
77+
absolute_local_path = os.path.abspath(local_path)
78+
79+
if not os.path.isfile(absolute_local_path):
80+
raise ValueError(f"The local path '{absolute_local_path}' is not a file.")
81+
82+
# Assuming the remote path is relative to the user's home directory
83+
remote_directory = os.path.dirname(remote_path)
84+
if remote_directory.startswith("."):
85+
remote_directory = remote_directory[1:] # Remove './' if present
86+
remote_directory_display = f"{remote_directory}" if remote_directory else "~"
87+
88+
click.echo(
89+
f"Sending file from {absolute_local_path} to pod {pod_id}:{remote_path}..."
90+
)
91+
with ssh_cmd.SSHConnection(pod_id) as ssh:
92+
ssh.put_file(absolute_local_path, remote_path)
93+
click.echo(
94+
f"File sent successfully to {remote_directory_display} on pod {pod_id}."
95+
)
96+
click.echo(f"To access the file, use: cd {remote_directory_display}. Type pwd to make sure you get put in the right directory.")
97+
98+
except Exception as e:
99+
click.echo(f"Failed to send file: {e}", err=True)
100+
101+
102+
@pod_cli.command("download")
103+
@click.argument("pod_id", required=True)
104+
@click.argument("remote_path", required=True)
105+
@click.argument("local_path", required=True)
106+
def download_file(pod_id, remote_path, local_path):
107+
"""
108+
Download a file from a specified pod to local machine.
109+
...
110+
"""
111+
try:
112+
absolute_local_path = os.path.abspath(local_path)
113+
114+
click.echo(
115+
f"Downloading file from pod {pod_id}:{remote_path} to {absolute_local_path}..."
116+
)
117+
with ssh_cmd.SSHConnection(pod_id) as ssh:
118+
ssh.get_file(remote_path, absolute_local_path)
119+
click.echo(f"File downloaded successfully to {absolute_local_path}.")
120+
121+
except Exception as e:
122+
click.echo(f"Failed to download file: {e}", err=True)
123+
click.echo(f"Ensure that the remote path exists on pod {pod_id}. \nAnd that the arguments are correct. \nFor example: runpod pod download 1234 /home/REMOTE_POD_PATH/file.txt /home/LOCAL_PATH/file.txt")

0 commit comments

Comments
 (0)